﻿<UserControl x:Class="GACManager.GACManagerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
             xmlns:GACManager="clr-namespace:GACManager"
             xmlns:apexBehaviours="clr-namespace:Apex.Behaviours;assembly=Apex"
             xmlns:apexConverters="clr-namespace:Apex.Converters;assembly=Apex"
             xmlns:apexControls="clr-namespace:Apex.Controls;assembly=Apex"
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="600">
    
    <UserControl.Resources>
        <apexConverters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

        <GACManager:GACManagerViewModel x:Key="MainViewModel" />

        <!-- Key image sources - only loaded once. -->
        <BitmapImage x:Key="ImageSourceRefresh" UriSource="/GACManager;component/Images/Refresh.png" />
        <BitmapImage x:Key="ImageSourceInstallAssembly" UriSource="/GACManager;component/Images/InstallAssembly.png" />
        <BitmapImage x:Key="ImageSourceCopy" UriSource="/GACManager;component/Images/Copy.png" />
        <BitmapImage x:Key="ImageSourceProperties" UriSource="/GACManager;component/Images/Properties.png" />
        <BitmapImage x:Key="ImageSourceUninstallAssembly" UriSource="/GACManager;component/Images/UninstallAssembly.png" />
        <BitmapImage x:Key="ImageSourceOpenFolder" UriSource="/GACManager;component/Images/OpenFolder.png" />
        <BitmapImage x:Key="ImageSourceDetails" UriSource="/GACManager;component/Images/Details.png" />
        <BitmapImage x:Key="ImageSourceHelp" UriSource="/GACManager;component/Images/Help.png" />
        
        <!-- A style for small icons. -->
        <Style x:Key="StyleIcon" TargetType="{x:Type Image}">
            <Setter Property="Width" Value="16" />
            <Setter Property="Stretch" Value="Uniform" />
            <Setter Property="RenderOptions.BitmapScalingMode" Value="NearestNeighbor" />

            <!-- Set the style triggers. -->
            <Style.Triggers>
                
                <!-- Fake a gray out of images in disabled toolbar buttons. -->
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type UIElement},
                    AncestorLevel=1}, Path=IsEnabled}" Value="False">
                    <Setter Property="Opacity" Value="0.3"></Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>

    </UserControl.Resources>
    
    <Grid DataContext="{StaticResource MainViewModel}">
        <DockPanel>
            
            <!-- The top of the dock panel will hold a toolbar and a search box. -->
            <apexControls:ApexGrid DockPanel.Dock="Top" Columns="Auto,*,Auto" SnapsToDevicePixels="True" UseLayoutRounding="False">

                <!-- The top of the dock panel is a toolbar. -->
                <ToolBar Grid.Column="0" ToolBarTray.IsLocked="True">
                    
                    <!-- The first set of buttons will be for commands that are always available. -->
                    <Button 
                        ToolTip="Refresh the list of Assemblies"
                        Command="{Binding RefreshAssembliesCommand}">
                        <Image Source="{StaticResource ImageSourceRefresh}" Style="{StaticResource StyleIcon}" />
                    </Button>

                    <Button 
                        ToolTip="Install a new assembly"
                        Command="{Binding InstallAssemblyCommand}">
                        <Image Source="{StaticResource ImageSourceInstallAssembly}" Style="{StaticResource StyleIcon}" />
                    </Button>

                    <Button 
                        ToolTip="Help and Project Home"
                        Command="{Binding HelpCommand}">
                        <Image Source="{StaticResource ImageSourceHelp}" Style="{StaticResource StyleIcon}" />
                    </Button>
                    
                    <Separator />

                    <!-- The next set of commands are assembly specific.-->
                    <Button 
                        ToolTip="Show Details" 
                        Command="{Binding ShowAssemblyDetailsCommand}"
                        CommandParameter="{Binding SelectedAssembly}">
                        <Image Source="{StaticResource ImageSourceDetails}" Style="{StaticResource StyleIcon}" />
                    </Button>
                    
                    <Button 
                        ToolTip="Copy Display Name (e.g. for gacutil)" 
                        Command="{Binding CopyDisplayNameCommand}"
                        CommandParameter="{Binding SelectedAssembly}">
                        <Image Source="{StaticResource ImageSourceCopy}" Style="{StaticResource StyleIcon}" />
                    </Button>
                    
                    <Button 
                        ToolTip="File Properties" 
                        Command="{Binding ShowFilePropertiesCommand}"
                        CommandParameter="{Binding SelectedAssembly}">
                        <Image Source="{StaticResource ImageSourceProperties}" Style="{StaticResource StyleIcon}" />
                    </Button>

                    <Button 
                        ToolTip="Uninstall the selected assembly"
                        Command="{Binding UninstallAssemblyCommand}"
                        CommandParameter="{Binding SelectedAssembly}">
                        <Image Source="{StaticResource ImageSourceUninstallAssembly}" Style="{StaticResource StyleIcon}" />
                    </Button>
                    
                    <Button 
                        ToolTip="Open assembly location"
                        Command="{Binding OpenAssemblyLocationCommand}"
                        CommandParameter="{Binding SelectedAssembly}">
                        <Image Source="{StaticResource ImageSourceOpenFolder}" Style="{StaticResource StyleIcon}" />
                    </Button>
                    
                </ToolBar>

                <!-- The main search box. -->
                <apexControls:SearchTextBox
                    Grid.Column="2" CueText="Search" Width="200" Margin="4"
                    Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" />

            </apexControls:ApexGrid>
            
            
            
            <!-- The bottom of the dock panel is a status bar. -->
            <StatusBar DockPanel.Dock="Bottom">
                <StatusBarItem>
                    <TextBlock Text="{Binding StatusInfo}" />
                </StatusBarItem>
                <Separator />
                <StatusBarItem>
                    <TextBlock Text="{Binding GacUtilStatusInfo}" />
                </StatusBarItem>
            </StatusBar>
            
            <Grid>
            
            <!-- The main list view of assemblies. -->
                <apexControls:ApexGrid Columns="*">
                    <ListView ItemsSource="{Binding AssembliesCollectionView}" SelectedItem="{Binding SelectedAssembly}"
                              MouseDoubleClick="ListView_MouseDoubleClick">

                        <i:Interaction.Behaviors>
                            <apexBehaviours:ListViewItemContextMenuBehaviour x:Name="parent">
                                <apexBehaviours:ListViewItemContextMenuBehaviour.ContextMenu>
                                    <ContextMenu>
                                        <MenuItem 
                                            Header="Show Details" 
                                            Command="{Binding ShowAssemblyDetailsCommand, Source={StaticResource MainViewModel}}"
                                            CommandParameter="{Binding}">
                                            <MenuItem.Icon>
                                                <Image Source="{StaticResource ImageSourceDetails}" Style="{StaticResource StyleIcon}" />
                                            </MenuItem.Icon>
                                        </MenuItem>
                                        <MenuItem 
                                            Header="Copy Display Name (e.g. for gacutil)" 
                                            Command="{Binding CopyDisplayNameCommand, Source={StaticResource MainViewModel}}"
                                            CommandParameter="{Binding}">
                                            <MenuItem.Icon>
                                                <Image Source="{StaticResource ImageSourceCopy}" Style="{StaticResource StyleIcon}" />
                                            </MenuItem.Icon>
                                        </MenuItem>
                                        <MenuItem 
                                            Header="Uninstall"
                                            Command="{Binding UninstallAssemblyCommand, Source={StaticResource MainViewModel}}" 
                                            CommandParameter="{Binding}">
                                            <MenuItem.Icon>
                                                <Image Source="{StaticResource ImageSourceUninstallAssembly}" Style="{StaticResource StyleIcon}" />
                                            </MenuItem.Icon>
                                        </MenuItem>
                                        <MenuItem 
                                            Header="File Properties" 
                                            Command="{Binding ShowFilePropertiesCommand, Source={StaticResource MainViewModel}}"
                                            CommandParameter="{Binding}">
                                            <MenuItem.Icon>
                                                <Image Source="{StaticResource ImageSourceProperties}" Style="{StaticResource StyleIcon}" />
                                            </MenuItem.Icon>
                                        </MenuItem>
                                        <MenuItem 
                                            Header="Open Containing Folder" 
                                            Command="{Binding OpenAssemblyLocationCommand, Source={StaticResource MainViewModel}}"
                                            CommandParameter="{Binding}">
                                            <MenuItem.Icon>
                                                <Image Source="{StaticResource ImageSourceOpenFolder}" Style="{StaticResource StyleIcon}" />
                                            </MenuItem.Icon>
                                        </MenuItem>
                                    </ContextMenu>
                                </apexBehaviours:ListViewItemContextMenuBehaviour.ContextMenu>
                            </apexBehaviours:ListViewItemContextMenuBehaviour>
                        </i:Interaction.Behaviors>
                        
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Name">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <apexControls:ApexGrid Columns="Auto,*">
                                                <Image 
                                                Source="/GACManager;component/Images/AssemblyIcon.png" Width="16" Height="16"
                                                   RenderOptions.BitmapScalingMode="Linear" Margin="0,2,8,2"/>
                                                <TextBlock Grid.Column="1" Text="{Binding DisplayName}" />
                                            </apexControls:ApexGrid>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn Header="Version" DisplayMemberBinding="{Binding Version}" />
                                <GridViewColumn Header="Public Key Token" DisplayMemberBinding="{Binding PublicKeyToken}" />
                                
                                <!-- Runtime version is currently disabled.
                                <GridViewColumn Header="RuntimeVersion" DisplayMemberBinding="{Binding RuntimeVersion}" />
                                 -->
                                <GridViewColumn Header="Culture" DisplayMemberBinding="{Binding Culture}" />
                                <GridViewColumn Header="Processor Architecture" DisplayMemberBinding="{Binding ProcessorArchitecture}" />
                                <GridViewColumn Header="Path" DisplayMemberBinding="{Binding Path}" />
                                <GridViewColumn Header="Custom" DisplayMemberBinding="{Binding Custom}" />
                            </GridView>
                        </ListView.View>
                    </ListView>
                    
                    <Border Background="#ffffff" Visibility="{Binding RefreshAssembliesCommand.IsExecuting, Converter={StaticResource BooleanToVisibilityConverter}}">

                        <apexControls:ApexGrid Rows="Auto,Auto" HorizontalAlignment="Center" VerticalAlignment="Center">
                            
                            <apexControls:CircularProgressBar
                                Grid.Row="0"
                                Width="32" Height="32" HorizontalAlignment="Center" />
                            
                            <TextBlock
                                Grid.Row="1"
                                Text="Loading Assembly Details..."
                                HorizontalAlignment="Center"
                                Margin="4" />

                        </apexControls:ApexGrid>
                    </Border>
                    
                </apexControls:ApexGrid>
            
           </Grid>
        </DockPanel>
        
            
    </Grid>
</UserControl>
